import Mock from 'mockjs'

const List = []
const count = 100 
const ListSys = []


for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',  
    tag_name: '标签@integer(1, 100)'
  }))
}

for (let i = 0; i < count; i++) {
  ListSys.push(Mock.mock({
    id: '@increment',  
    tag_name: '系统标签@integer(1, 100)'
  }))
}

export default [
  {
    url: '/project/system/sys_tags/list',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  }, 
  { 
    url: '/project/system/sys_tags/syslist',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = ListSys.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/project/system/sys_tags/detail',
    type: 'get',
    response: config => {
      const { id } = config.query
      for (const article of List) {
        if (article.id === +id) {
          return {
            code: 20000,
            data: article
          }
        }
      }
    }
  }, 

  {
    url: '/project/system/sys_tags/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/project/system/sys_tags/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/project/system/sys_tags/treelist',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: {
          items:[{
            label: '顶级部门',
            id: 1,
            children: [{
              label: '运营部',
              id: 2,
              children: [{
                label: '1组',
                id: 3
              }]
            }]
          }]
        }
      }
    }
  },

  {
    url: '/project/system/sys_tags/delete',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

